/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.lang.reflect.Field;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

/**
 *
 * @author ronald
 */
public class Query {
    
    public boolean insertarExperto(String tabla,Object objeto) throws IllegalArgumentException, SQLException, IllegalAccessException {

      boolean insertado=false;
        
        Class clase = objeto.getClass();
        Field[] userfield = clase.getDeclaredFields();
        
        String nombres="";
        String campos="";
          for(int x=0;x<userfield.length;x++){
              userfield[x].setAccessible(true);
          }
        for(int x=0;x<userfield.length-1;x++){
       
            nombres+=userfield[x].getName()+",";
        }
        
        nombres+=userfield[userfield.length-1].getName();
    
        for(int x=0;x<=userfield.length-1;x++){
          
              campos += "'" + userfield[x].get(objeto)+"',";
        }
       
        campos=campos.substring(0, campos.length()-1);
        String sql="insert into"+" "+tabla+" "+" "+"("+nombres+") VALUES ("+campos.trim()+")";
        Conexion cn=new Conexion();
        insertado=cn.insertar(sql);
            
        
        cn.desconectar();
        
        return insertado;
        
    }
    
    public ResultSet consultarExperto(String tabla,String campos,String condiciones) throws SQLException {
        Conexion cn=new Conexion();
        String sql="select "+campos+" from "+" "+tabla+" "+condiciones;
        ResultSet rs=cn.consulta(sql);
        cn.desconectar();
        return rs;
    }
     
}
